import java.util.*;
import java.io.*;

public class Practice1{
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static void main (String[] args)throws IOException{
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] arr = new int[n][m];
        for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                arr[i][j] = in.nextInt();
            }
        }
        long[] r = new long[n];
        long[] l = new long[m];
        for(int i = 0;i < n;i++){
            long sum = 0;
            for(int j = 0;j < m;j++){
                sum += arr[i][j];
            }
            r[i] = sum;
        }
        for(int i = 0;i < m;i++){
            long sum = 0;
            for(int j = 0;j < n;j++){
                sum += arr[j][i];
            }
            l[i] = sum;
        }
        for(int i = 0;i < n;i++){

            for(int j = 0;j < m;j++){
                long sum = l[j] + r[i] - arr[i][j];
                out.print(sum + " ");
            }
            out.println();
        }




        out.close();
    }
}



class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException{
        return bf.readLine();
    }

    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
}